package org.abox.tools.ant.taskdefs.mks.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tools.ant.BuildException;

import com.mks.api.Command;
import com.mks.api.response.APIException;
import com.mks.api.response.Response;

/**
 * Executes 'api ping' command and uses to check the MKS Server connection.
 *
 * @author Oleksandr_Korobka
 *
 */
public class APIPingTask extends BaseTask {

	private static final Log LOG = LogFactory.getLog(BaseTask.class);

	@Override
	public void execute() throws BuildException {
		Command ping = new Command("api", "ping");

	    // Execute the ping
		Response res;
		try {
			res = runCommand(ping);
			LOG.info(res.getCommandString() + " returned exit code " + res.getExitCode());
		} catch (APIException e) {
			throw new BuildException("API ping faulre: ", e);
		}

	}

}
